package printer;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import data.Game;
import data.GameList;
import data.Player;
import data.TournamentList;

public class ResultPrinter {
	
	public static void printResultList(TournamentList tList, String fileName){
		try {
			PrintWriter pw = new PrintWriter (fileName, "UTF-8");
			for (int i = 0; i < tList.getPlayers ().size (); i++){
				Player p = tList.getPlayers ().get (i);
				pw.println (p.name () + " " + p.points ());
			}
			pw.close ();
		} catch (FileNotFoundException e) {
			e.printStackTrace ();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
	
	public static void printNextTour(GameList gList, String fileName){
		PrintWriter pw = null;
		try {
			pw = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true)));
			for (int i = 0; i < gList.getGames ().size (); i++){
				Game g = gList.getGames ().get (i);	
				if (g == null){
					continue;
				}
				if (g.getPlayers ().length == 3){
					String players = (g.getPlayers ())[0].name () + " " + 
							(g.getPlayers ())[1].name ()+ " " +
							(g.getPlayers ())[2].name ();
					pw.println(players);
				}				
			}		    		    
		} catch (IOException e) {
		    //oh noes!
		} finally {
		    if (pw != null) {
		        pw.close();
		    }
		}		
	}
	
	
}
